package topic;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import utils.RabbitMqUtils;

import java.io.IOException;

public class Provider {
    public static void main(String[] args) throws IOException {
        //获取连接对象
        Connection connection = RabbitMqUtils.getConnection();
        //获取通道对象
        Channel channel = connection.createChannel();
        //通过通道声明（创建）交换机
        /*参数1：交换机的名称 参数2：topic ：路由模型--动态路由*/
        channel.exchangeDeclare("topics", "topic");
        //发送消息
        String routingkey="user.save";
        /*参数1：交换机名称 参数2：路由的key*/
        channel.basicPublish("topics", routingkey, null,
                ("这是topic动态路由模型 routekey：{"+routingkey+"} 发送的消息").getBytes());
        //关闭连接资源
        RabbitMqUtils.closeConnectionAndChannel(connection,channel);
    }
}
